package inline;

import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Environment;
import android.util.Log;

import java.io.File;
import java.io.IOException;

public class StorageUtils {
    public static File l(Context arg4) {
        File v0 = new File(new File(new File(new File(Environment.getExternalStorageDirectory(), "Android"), "data"), arg4.getPackageName()), "cache");
        if (!v0.exists()) {
            if (!v0.mkdirs()) {
                Log.w("StorageUtils", "Unable to create external cache directory");
                return null;
            }

            try {
                new File(v0, ".nomedia").createNewFile();
            } catch (IOException v1) {
                Log.i("StorageUtils", "Can\'t create \".nomedia\" file in application external cache directory");
            }
        }

        return v0;
    }

    public static File e(Context arg5) {
        File v0_3;
        String v0_1;
        File v1 = null;
        try {
            v0_1 = Environment.getExternalStorageState();
        } catch (NullPointerException v0) {
            v0_1 = "";
        }

        if ("mounted".equals(v0_1)) {
            int v0_2 = arg5.checkCallingOrSelfPermission("android.permission.WRITE_EXTERNAL_STORAGE") == PackageManager.PERMISSION_GRANTED ? 1 : 0;
            if (v0_2 == 0) {
                v0_3 = v1;
            } else {
                v0_3 = StorageUtils.l(arg5);
            }
        } else {
            v0_3 = v1;
        }

        if (v0_3 == null) {
            v0_3 = arg5.getCacheDir();
        }

        if (v0_3 == null) {
            String v1_1 = "/data/data/" + arg5.getPackageName() + "/cache/";
            Log.w("StorageUtils", String.format("Can\'t define system cache directory! \'%s\' will be used.", v1_1));
            v0_3 = new File(v1_1);
        }

        return v0_3;
    }
}
